set more off

use "dataset_nashville panel", clear

foreach x in ideoself1 ideoself2 {
	su `x'
	replace `x' = (`x'-r(min))/(r(max)-r(min))
}



gen priorideoself = ideoself1

gen mysub = !mi(votebarry1) & !mi(votebarry2) & !mi(ideoself1) & !mi(ideoself2)

drop id
gen id = _n

drop wave

reshape i id
reshape j wave 1 2
reshape xij knowbarrymorelib votebarry ideoself
reshape xi priorideoself learnedbarrymorelib `X' mysub
reshape long

xtset id wave

gen post = wave - 1
gen lvotebarryXlearn = l.votebarry*learn
gen priorideoselfXlearn = priorideoself*learn
gen priorideoselfXpost = priorideoself*post
gen ideoselfXpost = ideoself*post
gen lvotebarry = l.votebarry

label variable ideoself "Conservatism"
label variable priorideoself "Prior conservatism"
label variable lvotebarryXlearn "Prior vote X learned"
label variable learned "Learned"
label variable priorideoselfXlearn "Prior conservatism X learned"
label variable lvotebarry "Prior vote"
label variable ideoselfXpost "Conservatism X post"
label variable post "Post"

eststo clear

eststo: reg votebarry ideoself post ideoselfXpost, cl(id)
eststo: reg votebarry ideoself post ideoselfXpost if mysub==1, cl(id)
eststo: reg votebarry priorideoself lvotebarry if mysub==1, cl(id)
eststo: reg votebarry priorideoself lvotebarry if !mi(learned), cl(id)
eststo: reg votebarry priorideoself priorideoselfXlearn learn lvotebarry lvotebarryXlearn, cl(id)
lincom priorideoself + priorideoselfXlearn + learn
lincom priorideoselfXlearn + learn

#delimit;

esttab
	using "table 3.tex"
	,
		replace
		label
		width(\textwidth)		
		gap
		booktabs
		collabels(none)
		nomtitles
		eqlabels(none)
		cells(b(fmt(2) star) se(par))		
		order(ideoself post ideoselfXpost priorideoself learnedbarrymorelib priorideoselfXlearn lvotebarry lvotebarryXlearn)
		stats(
			N
			,
				fmt(%20.00fc)
				label("Sample size")
		)		
		;

#delimit cr
